package com.example.myapplication.di

import android.content.Context
import androidx.room.Room
import com.example.myapplication.data.database.StorageDatabase
import com.example.myapplication.data.database.StorageItemDao
import com.example.myapplication.data.database.StorageSpaceDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/**
 * 数据库依赖注入模块
 */
@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {
    
    /**
     * 提供Room数据库实例
     */
    @Provides
    @Singleton
    fun provideStorageDatabase(@ApplicationContext context: Context): StorageDatabase {
        return Room.databaseBuilder(
            context.applicationContext,
            StorageDatabase::class.java,
            "storage_database"
        )
            .fallbackToDestructiveMigration() // 开发期间使用，生产环境应使用迁移策略
            .build()
    }
    
    /**
     * 提供StorageSpaceDao
     */
    @Provides
    fun provideStorageSpaceDao(database: StorageDatabase): StorageSpaceDao {
        return database.storageSpaceDao()
    }
    
    /**
     * 提供StorageItemDao
     */
    @Provides
    fun provideStorageItemDao(database: StorageDatabase): StorageItemDao {
        return database.storageItemDao()
    }
} 